<template>
  <div v-loading="loading" class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('内部治理架构') }}</span>
    </div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('公司治理')" prop="companyGovernment">
            <el-input v-model="form.companyGovernment" type="textarea" :placeholder="$t('公司治理')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('内控机制')" prop="controlMechanism">
            <el-input v-model="form.controlMechanism" type="textarea" :placeholder="$t('内控机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('管理制度')" prop="manageMechanism">
            <el-input v-model="form.manageMechanism" type="textarea" :placeholder="$t('管理机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('项目遴选机制')" prop="projectSelect">
            <el-input v-model="form.projectSelect" type="textarea" :placeholder="$t('项目遴选机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('投资决策机制')" prop="investmentDecision">
            <el-input v-model="form.investmentDecision" type="textarea" :placeholder="$t('投资决策机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('激励约束机制')" prop="incentiveRestraint">
            <el-input v-model="form.incentiveRestraint" type="textarea" :placeholder="$t('激励约束机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('跟进投资机制')" prop="followInvestment">
            <el-input v-model="form.followInvestment" type="textarea" :placeholder="$t('跟进投资机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('资产托管机制')" prop="assetsTrusteeship">
            <el-input v-model="form.assetsTrusteeship" type="textarea" :placeholder="$t('资产托管机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('风险控制机制')" prop="riskControl">
            <el-input v-model="form.riskControl" type="textarea" :placeholder="$t('风险控制机制')" show-word-limit maxlength="1000" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: center;margin-top: 10px;">
      <!--保存 取消按钮-->
      <save-btn has-permi="gp:insideFramework" :cancel-show="false" />
    </div>
  </div>
</template>

<script>
    import { saveGpInsideFramework, getGpInsideFrameworkByGpId } from '@/api/fund/gp/insideFramework/gpInsideFramework'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 遮罩层
                loading: false,
                // 表单校验
                rules: {
                  companyGovernment: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  controlMechanism: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  manageMechanism: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  projectSelect: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  investmentDecision: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  incentiveRestraint: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  followInvestment: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  assetsTrusteeship: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  riskControl: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
                },
                queryParams: {
                  gpId: this.$route.query.gpId
                },
                // 是否隐藏保存等按钮
                btnHide: false
            }
        },
        created() {
          this.init(this.queryParams)
        },
        methods: {
            // 初始化数据
            init(data) {
                if (data != null) {
                  getGpInsideFrameworkByGpId(data.gpId).then(response => {
                        if (response.data != null) {
                          this.form = response.data
                        } else {
                          this.reset()
                        }
                        this.loading = false
                    })
                } else {
                    this.reset()
                    this.loading = false
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    gpId: this.$route.query.gpId,
                    companyGovernment: undefined,
                    controlMechanism: undefined,
                    manageMechanism: undefined,
                    projectSelect: undefined,
                    investmentDecision: undefined,
                    incentiveRestraint: undefined,
                    followInvestment: undefined,
                    assetsTrusteeship: undefined,
                    riskControl: undefined,
                    remark: undefined,
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                  this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        this.loading = true
                        saveGpInsideFramework(this.form).then(response => {
                            if (response.code === 200) {
                                this.msgSuccess(this.$t('保存成功'))
                                this.closeForm()
                            } else {
                                this.msgError(response.msg)
                            }
                            this.loading = false
                        })
                    } else {
                      this.locationError(document)
                    }
                })
           }

        }

    }
</script>
